<template>
  <div class='page'>
    <el-card>
      <p class="title">用户登录</p>
      <el-form ref="form"
               :model="form"
               :rules="rules"
               label-width="80px">
        <el-form-item label="用户名"
                      prop="name">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="密码"
                      prop="pwd">
          <el-input v-model="form.pwd"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="handleSubmit('form')"
                     style="width:100%;height:50px;margin-top:30px"
                     type="primary">登录</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  props: {},
  components: {},
  data() {
    return {
      form: {
        name: '',
        pwd: "",
        head: require("@/assets/logo.png"),
        token: '**token**'
      },
      rules: {
        name: [
          { required: true, message: '请输入账号', trigger: 'blur' }
        ],
        pwd: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ],
      }
    }
  },
  mounted() { },
  methods: {
    handleSubmit(form) {
      this.$refs[form].validate(flag => {
        if (flag) {
          this.$actions.setGlobalState({
            user: this.form
          });
          this.$store.commit("setUser", this.form)
          this.$router.push(this.$route.query.redirect)
        }
      })
    }
  }
}
</script>

<style lang='scss' scoped>
.title {
  font-weight: 800;
  color: #333;
  font-size: 38px;
  text-align: center;
  margin-bottom: 30px;
}
.el-card {
  width: 90%;
  padding: 50px;
  min-height: 500px;
  margin: 0 auto;
}
</style>